package com.example.cardemo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import android.webkit.WebView
import com.example.cardemo.bean.NewslistBean

class NewsDetailsActivity : AppCompatActivity() {

    private lateinit var data: NewslistBean.NewslistData
    private lateinit var toolbar: Toolbar
    private lateinit var webView: WebView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_news_details)

        // 初始化控件
        toolbar = findViewById(R.id.toolbar)
        webView = findViewById(R.id.webview)

        // 获取数据
        data = intent.getSerializableExtra("data") as NewslistBean.NewslistData

        if (data != null) {
            toolbar.title = data.title
            webView.loadUrl(data.url)
        }

        toolbar.setOnClickListener {
            finish()
        }
    }

    private fun enableEdgeToEdge() {
        ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            view.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
    }
}